This disclosure relates generally to pinned memory and, more particularly, to techniques for managing pinned memory in a data processing system.
In computer systems, memory management units (MMUs) may be configured to employ paging to store and retrieve data from secondary storage for use in primary storage. In a known memory management approach, a pager (e.g., implemented within an MMU) retrieves data from secondary storage in blocks, referred to as pages. In virtual memory implementations, paging allows an OS to use secondary storage for data that does not fit into primary storage. When an executing program tries to access pages that are not currently mapped to primary storage, a page fault occurs, and an MMU attempts to handle the page fault in a manner that is invisible to the executing program. For example, an MMU may: determine a location of requested data in secondary storage; obtain an available page frame in primary storage for the requested data; load the requested data into the available page frame in the primary storage; update a page table (PT) to show where the new data is located; and return control to the executing program to transparently retry the instruction that caused the page fault.
Until there is not enough primary storage to store all the requested data, the process of obtaining an available page frame does not usually involve removing another page from the primary storage. If all page frames are non-empty, obtaining an available page frame requires choosing a page frame that includes data that is to be emptied. If the data in the page frame that is to be emptied has been modified since it was read into primary storage (i.e., the data is “dirty”), the dirty data must be written back to a designated location in secondary storage before the page frame in primary storage is freed. If the data in the page frame to be emptied is not dirty, the contents of the page in primary storage is the same as the contents of the page in secondary storage, and the page does not need to be written back to the secondary storage. If a reference is subsequently made to a page that was paged-out from primary storage to secondary storage, a page fault will occur, an available page frame is obtained, and the contents of the page in the secondary storage is read into the available page frame. Most MMUs use some variation of the least recently used (LRU) page replacement algorithm to select pages for replacement.
Various operating systems (e.g., Advanced Interactive eXecutive (AIX)) allow for pinning a memory region, which causes the memory region to be maintained in primary storage (e.g., random access memory (RAM)) and which prevents the memory region from being considered by the pager as a candidate for being paged-out to secondary storage (e.g., a hard disk drive (HHD)). Thus, pinning a memory region prohibits a pager from stealing pages from the pinned memory region. In most OSs, memory regions defined in either system space or user space may be pinned. When an inadequate amount of pinned memory is available, loadable modules (e.g., device drivers and/or kernel extensions) may fail to configure. As is known, when a page fault occurs in an interrupt environment or with interrupts disabled in a process environment, an associated OS may crash. To avoid page faults in an interrupt environment or with interrupts disabled in a process environment, device drivers and/or kernel extensions pin memory pages to make sure data is resident in primary storage (i.e., main memory). After a memory region is pinned, accessing the memory region does not result in a page fault.
In computing, a kernel extension (or loadable kernel module) is an object file that includes code to extend a base kernel (OS kernel). Kernel extensions are typically used to add support for new hardware, file systems, and/or system calls. When the functionality provided by a kernel extension is no longer required, the kernel extension can be unloaded from main memory in order to free memory and other resources. In computing, a device driver is a computer program that allows higher-level computer programs to interact with a hardware device. A device driver typically communicates with an associated hardware device through a computer bus or communication subsystem. When a calling program invokes a routine in a device driver, the device driver issues commands to an associated hardware device. Once the hardware device sends data back to the device driver, the device driver may invoke routines in the calling program. In general, device drivers are hardware-dependent and OS-specific. Device drivers usually provide interrupt handling required for any necessary asynchronous time-dependent hardware interface.